package com.weds.frame.common.util;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * Description:
 * Author: LiuWenQing
 * Datetime: 2023/4/4 17:27
 */
@Component
public class LogUtil {

    @Autowired(required = false)
    private HttpServletRequest request;

    public void handleRequest(Object... args) {
        String argStr = "";
        for (Object arg : args) {
            if (Objects.nonNull(arg)
                    && !StringUtils.isEmpty(arg.toString())) {
                argStr += arg.toString() + ",";
            }
        }
        if (argStr.lastIndexOf(",") == argStr.length() - 1) {
            argStr = argStr.substring(0, argStr.length() - 1);
        }
        request.setAttribute("logArgs", argStr);
//        InputStreamHttpServletRequestWrapper inputStreamHttpServletRequestWrapper = (InputStreamHttpServletRequestWrapper) request;
//        inputStreamHttpServletRequestWrapper.addHeader("logArgs", argStr);
    }
}
